package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.TMedicalOutpatientdoctorReceiverecord;
import com.ruoyi.system.domain.dto.OutInfoIdsDto;
import com.ruoyi.system.service.ITMedicalOutpatientdoctorReceiverecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TMedicalLisInfo;
import com.ruoyi.system.service.ITMedicalLisInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Lis检验管理Controller
 *
 * @author ruoyi
 * @date 2021-09-28
 */
@RestController
@RequestMapping("/system/lisinfo")
public class TMedicalLisInfoController extends BaseController {
    @Autowired
    private ITMedicalLisInfoService tMedicalLisInfoService;

    @Autowired
    private ITMedicalOutpatientdoctorReceiverecordService itMedicalOutpatientdoctorReceiverecordService;

    /**
     * 查询Lis检验管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:lisinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMedicalLisInfo tMedicalLisInfo) {
        startPage();
        List<TMedicalLisInfo> list = tMedicalLisInfoService.selectTMedicalLisInfoList(tMedicalLisInfo);
        return getDataTable(list);
    }

    /**
     * 导出Lis检验管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:lisinfo:export')")
    @Log(title = "Lis检验管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMedicalLisInfo tMedicalLisInfo) {
        List<TMedicalLisInfo> list = tMedicalLisInfoService.selectTMedicalLisInfoList(tMedicalLisInfo);
        ExcelUtil<TMedicalLisInfo> util = new ExcelUtil<TMedicalLisInfo>(TMedicalLisInfo.class);
        return util.exportExcel(list, "Lis检验管理数据");
    }

    /**
     * 获取Lis检验管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:lisinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tMedicalLisInfoService.selectTMedicalLisInfoById(id));
    }

    /**
     * 新增Lis检验管理
     */
    @PreAuthorize("@ss.hasPermi('system:lisinfo:add')")
    @Log(title = "Lis检验管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMedicalLisInfo tMedicalLisInfo) {
        return toAjax(tMedicalLisInfoService.insertTMedicalLisInfo(tMedicalLisInfo));
    }

    /**
     * 修改Lis检验管理
     */
    @PreAuthorize("@ss.hasPermi('system:lisinfo:edit')")
    @Log(title = "Lis检验管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMedicalLisInfo tMedicalLisInfo) {
        return toAjax(tMedicalLisInfoService.updateTMedicalLisInfo(tMedicalLisInfo));
    }

    /**
     * 执行
     */
    @Log(title = "Lis检验管理", businessType = BusinessType.UPDATE)
    @PutMapping("/zhixingcaozuo")
    public AjaxResult zhixingcaozuo(@RequestBody OutInfoIdsDto od) {
        TMedicalLisInfo tMedicalLisInfo = new TMedicalLisInfo();
        tMedicalLisInfo.setStatus(od.getStatus());
        String[] idss = od.getIdss();
        TMedicalOutpatientdoctorReceiverecord tm = new TMedicalOutpatientdoctorReceiverecord();
        for (String id : idss) {
            tMedicalLisInfo.setId(id);
            tMedicalLisInfoService.updateTMedicalLisInfo(tMedicalLisInfo);
            TMedicalLisInfo tMedicalLisInfo1 = tMedicalLisInfoService.selectTMedicalLisInfoById(id);
            tm.setOpdoctorreceiverecordid(tMedicalLisInfo1.getReceiverecordid());
            tm.setJiezhen(2l);
            itMedicalOutpatientdoctorReceiverecordService.updateTMedicalOutpatientdoctorReceiverecord(tm);
        }


        return toAjax(1);
    }

    /**
     * 删除Lis检验管理
     */
    @PreAuthorize("@ss.hasPermi('system:lisinfo:remove')")
    @Log(title = "Lis检验管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tMedicalLisInfoService.deleteTMedicalLisInfoByIds(ids));
    }
}
